import envs from '@/consts/environment';
import { getGlobal } from '@/utils/otherUtil';
const style =
  'font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 16px; color: #444; padding: 16px 0 0; line-height: 30px; font-weight: bold';

function colorLog(params) {
  log(`[c="color: ${params.color}"]${params.msg}[c]`);
}

class Logger {
  // 成功
  successful(msg, data) {
    if (!envs.log) return;
    var str = `✅ ${msg}`;
    msg && colorLog({ color: 'green', msg: str });
    if (data) {
      console.log(data);
    }
  }
  // 错误
  error(msg, data) {
    if (!envs.log) return;
    var str = `❌ ${msg}`;
    msg && colorLog({ color: 'red', msg: str });
    if (data) {
      console.log(data);
    }
  }

  // 输出
  info(msg, data) {
    if (!envs.log) return;
    var str = `🔵 ${msg}`;
    msg && colorLog({ color: 'blue', msg: str });
    if (data) {
      console.log(data);
    }
  }

  //警告
  warning(msg, data) {
    if (!envs.log) return;
    var str = `🟡 ${msg}`;
    msg && colorLog({ color: '#faad14', msg: str });
    if (data) {
      console.log(data);
    }
  }

  //连接地址
  link(name, url) {
    if (!envs.log) return;
    log(`${name}: _${url}_`);
  }

  //连接地址
  title(name) {
    if (!envs.log) return;
    log.l(`%c${name}`, style);
  }
}
var logger = new Logger();
getGlobal().logger = logger;
export default logger;
// logger.title('初始化')
// logger.successful('成功',{name:'xiaohong'})
// logger.error('错误',{code:500})
// logger.info('正常输出',{code:500})
// logger.warning('警告',{code:500})
// logger.link('百度','www.baidu.com')

// const style = 'font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; font-size: 13px; color: #444; padding: 16px 0 0; line-height: 30px; font-weight: bold'
// log.l('%cBold & italics', style)
// log('*this is italic* and _this is bold_.')
// log.l('%cInline code', style)
// log('this is code: `a == b == c`')
// log.l('%cColor', style)
// log('this is [c="color: red"]red[c]. this is [c="color: green"]green[c].')
// log.l('%cLearn more', style)
// log('_https://github.com/adamschwartz/log_')
